<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<link rel="stylesheet" href="{:ADDON_PUBLIC_PATH}/css/weuix.min.css" />
		<link rel="stylesheet" type="text/css" href="{:ADDON_PUBLIC_PATH}/css/jquery-weui.min.css"/>
		<link rel="stylesheet" type="text/css" href="{:ADDON_PUBLIC_PATH}/css/adinfo.css"/>
		<link rel="stylesheet" type="text/css" href="{:ADDON_PUBLIC_PATH}/css/iconfont1.css"/>
		<script type="text/javascript">
		//静态变量
		var SITE_URL = "{:SITE_URL}";
		var IMG_PATH = "__IMG__";
		var STATIC_PATH = "__STATIC__";
		var WX_APPID = "{$jsapiParams.appId}";
		var	WXJS_TIMESTAMP='{$jsapiParams.timestamp}'; 
		var NONCESTR= '{$jsapiParams.nonceStr}'; 
		var SIGNATURE= '{$jsapiParams.signature}';
	</script>
	<script src="{:ADDON_PUBLIC_PATH}/js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	</head>
	<body>
			<div class="bj">
				<img src="<if condition="$udata['photo_url']">{:get_file_url($udata['photo_url'])}<else/>{:ADDON_PUBLIC_PATH}/img/swiper-2.jpg</if>"/>
			</div>
			<div class="touxiang">
				<img src="<if condition="$udata['photo_url']">{:get_file_url($udata['photo_url'])}<else/>{:ADDON_PUBLIC_PATH}/img/swiper-2.jpg</if>"/>
			</div>
			<div class="box">
					<div class="weui_cells">
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<p>姓名</p>
							</div>
							<div class="weui_cell_ft">{$udata['username']}</div>
						</div>
						
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<p>班级</p>
							</div>
							<div class="weui_cell_ft">{$udata['class']}</div>
						</div>
					</div>
			</div>
			<div class="btnn" style="margin-top: 30px;">
				<a class="weui_btn weui_btn_warn" id="sub">确定</a>
				<a class="weui_btn weui_btn_warn iconfont icon-zhaoxiangji1" id="y"></a>
			</div>
		
		<div class="weui-footer" style="margin-top: 60px;">
		  <p class="weui-footer__links">
		    <a href="javascript:void(0);" class="weui-footer__link">微生活工作室</a>
		  </p>
		  <p class="weui-footer__text" style="border-radius: ;">Copyright © 20016-2017</p>
		</div>
	</body>
	<script src="{:ADDON_PUBLIC_PATH}/js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="{:ADDON_PUBLIC_PATH}/js/swiper.js" type="text/javascript" charset="utf-8"></script>
	<script src="{:ADDON_PUBLIC_PATH}/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		$(function(){
			$('.touxiang img').on('click', function(){
				var src = $('.touxiang img')[0].src;
				var pb1 = $.photoBrowser({
					  items: [
					    src
					  ]
					});
				pb1.open();
				$('.swiper-pagination').children('span').remove();
			});
		});
	</script>
	<script type="text/javascript">
        wx.config({
            debug: false,
            appId: WX_APPID,
            timestamp: WXJS_TIMESTAMP,
            nonceStr: NONCESTR,
            signature: SIGNATURE,
            jsApiList: ['checkJsApi', 'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone',
            'getLocation',
            'chooseImage',
            'uploadImage']
        });

        var img = '';
        $('#y').click(function(){
			wx.ready(function(){
				wx.chooseImage({
				    count: 1, // 默认9
				    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				    success: function (res) {
				             // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
				              img = res.localIds;
				              $('.touxiang img ').attr('src',img);
				              $('.bj img').attr('src',img);
				    }
				});
			});
		});

		$("#sub").click(function(){
			$.showLoading();
			/*上传图片*/
			if(img.length){
			    wx.uploadImage({
			        localId: img.toString(),
			        success: function (res) {
			        	$.hideLoading();
			             $.ajax({
					    url:"{:U('studPhoto',array('aid'=>I('get.aid'),'uid'=>I('get.uid')))}",
					    type:"post",
					    dataType:"json",
					    data:{"img":res.serverId},
					    success:function(data){
					     	$.hideLoading();
				            console.log(data);
				            if (data.status == 1) {
				                 $.toast(data.info); 
				                 setTimeout(function(){
				                 	location.href = "{:U('photoIndex',array('aid'=>I('get.aid')))}";
				                 },1500);
				            } else {
				                 $.toast(data.info, "forbidden");
				            }
					    },
					    error:function(){
					      	$.hideLoading();
	      	    			$.toast("Eoor"); 
					    }
					});
			        },
			        fail: function (res) {
			          $.hideLoading();
	      	    	  $.toast("Eoor"); 
			        }
			      });
			}else{
				$.hideLoading();
	      	    $.toast("OK"); 
                setTimeout(function(){
                 	//  history.pushState("","","{:U('booksDetail',array('bid'=>I('get.bid')))}");  
                 	location.href = "{:U('photoIndex',array('aid'=>I('get.aid')))}";
                 	// window.history.go(-1);
               },1500);
			}  
		});
    </script>
</html>